package com.liangdemo.web.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author Mr.Liang
 * @date 2022/5/26 13:26
 */
@Component
@Aspect
public class Loggin {
    /**
     * 方法前执行
     *
     * @param joinPoint
     */
    @Before("execution(public * com.liangdemo.web.aop.loggerAspect.logger(..))")
    public void output(JoinPoint joinPoint) {
        //获取方法名
        joinPoint.getSignature().getName();
        //获取参数
        Object[] array = joinPoint.getArgs();
        System.out.println("方法执行之前：" + "方法名是：" + joinPoint.getSignature().getName() + "方法的参数是：" + Arrays.toString(joinPoint.getArgs()));
    }

    /**
     * 方法返回值
     */
    @AfterReturning(value = "execution( public * com.liangdemo.web.aop.loggerAspect.logger(..))", returning = "object")
    public void afterReturning(JoinPoint joinPoint, Object object) {
        //获取方法名
        joinPoint.getSignature().getName();
        System.out.println("方法执行完之后：" + "方法名是：" + joinPoint.getSignature().getName() + "方法的结果是：" + object);

    }


}
